﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ConnectToDatabase;

namespace QLGiayDep.Forms
{
    /// <summary>
    /// Interaction logic for WinNhaPP.xaml
    /// </summary>
    public partial class WinThemNhaPP : Window
    {
        private InsertDB insertDB;
        private SetID setID;
        string URL;
        //private InsertObjectClient insertObjectClient;
        //private UpdateObjectClient updateObjectClient;
        //private SetIDObjectClient setIDObjectClient;

        public WinThemNhaPP(string _url)
        {
            InitializeComponent();
            URL = _url;
            setID = (SetID)Activator.GetObject(typeof(SetID), URL + "SETID_OBJECT");
            txtMaNhaPP.Text = setID.GenerateMaNhaPP();
        }

        private void bntThemNhaPP_Click(object sender, RoutedEventArgs e)
        {
            int kt;
            insertDB = (InsertDB)Activator.GetObject(typeof(InsertDB), URL + "INSERTDB_OBJECT");
            kt = insertDB.InsertNhaPhanPhoi(txtMaNhaPP.Text, txtTenNhaPP.Text, 1);
            if (kt == -1)
                MessageBox.Show("Thêm nhà phân phối thất bại", "Lỗi");
            else
            {
                MessageBox.Show("Thêm nhà phân phối thành công Thành Công", "Thông Báo");
                txtMaNhaPP.Text = setID.GenerateMaNhaPP();
                txtTenNhaPP.Clear();
            }
                
        }

        private void bntThoatNhaPP_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
